package com.study.util;

import java.util.List;

import redis.clients.jedis.Jedis;

public class RedisList {

	public static void main(String[] args) {
		Jedis jedis = RedisUtil.getJedis();
		//想列表list中添加a,b,c,d,e,f
		jedis.lpush("list", "a","b","c","d","e","f");
		List<String> valueList = jedis.lrange("list", 0, -1);
		for (String value : valueList) {
			System.out.println(value);
		}
		
		//移除并获取list的第一个元素
		String firstVale = jedis.lpop("list");
		System.out.println("firstVale: " + firstVale);
		
		//获取list列表的长度
		long length = jedis.llen("list");
		System.out.println("length: " + length);
		
		//获取list列表中第二个元素
		String secondValue = jedis.lindex("list", 1);
		System.out.println("secondValue: " + secondValue);
		
		//将aa添加到list的第二个位置上
		jedis.lset("list", 1, "aa");
		valueList = jedis.lrange("list", 0, -1);
		for (String value : valueList) {
			System.out.println(value);
		}
		
		jedis.lpush("list", "a","a","a");
		//移除list列表中前三个值为a的元素
		jedis.lrem("list", 3, "a");
		valueList = jedis.lrange("list", 0, -1);
		for (String value : valueList) {
			System.out.println(value);
		}
		
		//保留list列表第三到第五的元素
		jedis.ltrim("list", 2, 4);
		for (String value : valueList) {
			System.out.println(value);
		}
		jedis.close();
	}
}
